//验收列表
function receiveList($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $$scope = $scope;
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;

    var dataInit = $CertusJsonAjax.dataInit("receive/receiveList",{contractCode:$("#contractCodeId").val()},pltlogColumns,'pltlogContainer','pltlogToolBarContainer');

    $$scope.receiveSearch = function(){
        dataInit.parameters = {
            contractCode:$("#contractCodeId").val()
        }
        dataInit.refresh(true);
    }

}
//添加验收
function addReceive($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $$scope = $scope;

    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;

    $routeParams.contractCode = $routeParams.contractCode.replace("@@", "/");
    $CertusFormAjax.ajax("receive/enterReceive", {
        contractCode: $routeParams.contractCode
    }, function (res) {
        $$scope.receive = {};
        $$scope.receive.contractCode = $routeParams.contractCode;
        $$scope.receive.supplieName = res.data.supplierName;

        //初始化 清单 datagrid
        var purchaselistOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '协议购买清单',
            datas: res.data.buying,
            columns: purchaselistColumns,
            gridContainer: 'purchaselistContainer',
            toolbarContainer: 'purchaselistToolBarContainer',
            // check: true,
            // checkWidth: 20,
            // onCheck : function(isChecked, record, grid, dataNo, row, extraCell, e){
            // 	var log = '<p>复选事件触发。是否复选：'+isChecked+'；触发行坐标：'+dataNo+'。</p>';
            // 	appendLog_2_1_11(log);
            // },
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var purchaselistGrid = $.fn.dlshouwen.grid.init(purchaselistOption);
        purchaselistGrid.load();

        $$scope.yesOrNoSelect = [
            {name: "是", code: "1"},
            {name: "否", code: "0"}
        ]
        $$scope.qualifiedSelect = [
            {name: "合格", code: "1"},
            {name: "不合格", code: "0"}
        ]

        var yslistOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            // loadURL:'url',
            exportFileName: '协议验收清单列表',
            datas:[],
            columns: yslistColumns,
            gridContainer: 'yslistContainer',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        yslistGrid = $.fn.dlshouwen.grid.init(yslistOption);
        yslistGrid.load();
    })

    $$scope.saveReceiveItem = function () {
        if(certusValidateNotnullPolyfill()){

            if(yslistGrid.exhibitDatas){
                yslistGrid.exhibitDatas.push($$scope.receiveItem);
            }else{
                yslistGrid.exhibitDatas = new Array();
                yslistGrid.exhibitDatas.push($$scope.receiveItem);
            }
            yslistGrid.refresh(false);

            var status = $(".shuplod").css('display');
            if (status == "none") {
                $(".shuplod").show();
            } else {
                $(".shuplod").hide();
            }
        }
    }

    $$scope.receiveSave = function(){
        if(certusValidateNotnull()){
            if(yslistGrid.exhibitDatas && yslistGrid.exhibitDatas.length > 0){
                if(!$scope.receive.isEquipment){
                    layer.msg("验收意见请选择");
                }
                if(!$scope.receive.working){
                    layer.msg("验收意见请选择");
                }
                if(!$scope.receive.informationComp){
                    layer.msg("验收意见请选择");
                }
                if(!$scope.receive.qualified){
                    layer.msg("验收意见请选择");
                }
                $$scope.receive.receiveItems = yslistGrid.exhibitDatas;
                $CertusJsonAjax.ajax("receive/receiveSave",$$scope.receive,function(res){
                    if(res.data == "success"){
                        history.back();
                    }
                })
            }else{
                layer.msg("请添加验收单");
            }
        }
    }
}
//验收 查看
function selReceive($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $$scope = $scope;
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;


    //1 0 1 0 互换
    $$scope.getWhether = function (a) {
        if (a == "1") {
            return "是";
        } else {
            return "否";
        }
    }

    $$scope.getQualified = function (a) {
        if (a == "1") {
            return "合格";
        } else {
            return "不合格";
        }
    }


    $CertusFormAjax.ajax("receive/selReceive",{checkCode:$routeParams.checkCode.replace("@@","/")},function(res){
        $$scope.receive =  res.data.receive;
        $$scope.receiveItems = res.data.receiveItems;
    })

}
